<?php
//Start session
session_start();
class user_model {
    
    function __construct(){

        //Include database connection details
        require_once '../include/connectDB.php';
        connectDB::warfarin_db();
    }
   
    function check_login($username, $password){
        $password = md5($password);
        $result = mysql_query("SELECT username, password, user_detail FROM users WHERE username = '$username' AND password = '$password'");
        $user_data = mysql_fetch_array($result);
        $no_rows = mysql_num_rows($result);  
            if ($no_rows == 1){
                $_SESSION['btnLogin'] = true;
                $_SESSION['username'] = $user_data['username'];
                return TRUE;
            }
            else{
                return FALSE;
            }
      }
      
     // Getting name
    public function get_fullname($id)
    {
        $result = mysql_query("SELECT user_detail FROM users WHERE id = '$id'");
        $user_data = mysql_fetch_array($result);
        echo $user_data['user_detail'];
    }
    // Getting session 
    public function get_session()
    {
        return $_SESSION['btnLogin'];
    }
    // Logout 
    public function user_logout()
    {
        $_SESSION['btnLogin'] = FALSE;
        session_destroy();
    } 
            
//    function getlogin($username, $password){
//        
//        $result = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = 'MD5($password)' ");
//        
//        if (($result -> num_rows() > 0)) {
//        
//            return $result->result();
//         }
//        else{
//            return false;
//        }  
}



